package com.project.contorller;

import com.project.bean.ChannelBane;
import com.project.bean.CutPagBean;
import com.project.bean.InvitationBane;
import com.project.bean.UserBean;
import com.project.dao.Impl.InvitationDaoImpl;
import com.project.service.IChannelService;
import com.project.service.IInvitationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;

@RestController
@RequestMapping("in")
public class InvitationController {
    @Autowired
    private IInvitationService service;

    @RequestMapping("findAll")
    public CutPagBean<InvitationBane> findByItem(int pageNo, Integer id, String name, String author, LocalDate startDate, LocalDate endDate){
        return service.findByItem(pageNo,id ,name,author,startDate,endDate);
    }
    @RequestMapping("add")
        public String add(String content,String name ,int chid, HttpServletRequest req){
        UserBean user = (UserBean) req.getSession().getAttribute("loginUser");
        ChannelBane channelBane = new ChannelBane();
        channelBane.setId(chid);
        InvitationBane in = new InvitationBane( name,user.getId(),channelBane.getId(),content);
        service.addInvitation(in);
            return "ok";
        }
        @RequestMapping("findById")
    public InvitationBane findById(int id){
        return service.findById(id);
    }
}
